const dbutil = require('../../../libs/MyDB');

module.exports = {

    // 验证登录信息
    checkLogin: async function (data) {
        if (data.username == '' || data.password == '') {
            return {
                code: 403,
                msg: "username or password is empty"
            }
        }
        let result = {}
        await dbutil.singleSelect('study_admin', 'password', `aname='${data.username}'`)
            .then(
                res => {
                    result = res
                }
            )

        if (!result.password) {
            return {
                code: 401,
                msg: "username is not exist"
            }
        } else {
            if (result.password != data.password) {
                return {
                    code: 402,
                    msg: "password is wrong"
                }
            } else {
                return {
                    code: 200,
                    msg: "login success",
                    url: "/backstage"
                }
            }
        }
    },
}